﻿<?php

define('ICON_BUG_CHECK','1');
class PhpSCup_div
{
	var $conn_id = '';
	
	var $div_data = array();

	var $div_icon = array();
	
	var $module_data = array();
	
	var $appname = '';

	var $appid = '';

	var $icondata_dir = '';
						
     function __construct($appid = '',$appname = '',$filedir='')
    {
        $this->PhpSCup_div($appid,$appname,$filedir);
    }

    function PhpSCup_div($appid = '',$appname = '',$filedir='')
    {
	    $this->div_data = include (ROOT_PATH . '/data/module/module_div.php');

	    $this->div_icon = include ($GLOBALS['SCup']->SCup_view_root. '/icon/icon.php');
		
		$this->get_module_data($filedir);
		
	    $this->appname = $appname;
		$this->appid = $appid;
        $this->icondata_dir = $GLOBALS['SCup']->SCup_view_root;

		if(empty($this->appname))
		{ 
		   if(!empty($this->appid))
		   {
		        foreach($this->module_data as $key => $value)
		        {
		           if($value['id']==$this->appid)
		           {
				     if(!isset($value['appname']))
					 {
					  $value['appname'] ='';
					 }
		           $this->appname = $value['appname'];		 
		           }		 		
		        }				   
		   }

		}
		
		if(empty($this->appname))
		{
		 $this->appname = $GLOBALS['SCup']->SCup_module_appname;
		}
			
    }

	function get_module_data($filedir='module/module_list.php') 
	{
	    if(empty($this->module_data))
		{
		if(empty($filedir))$filedir='module/module_list.php';
	    $this->module_data = include (ROOT_PATH . '/data/'.$filedir);
		}
		return $this->module_data;		
		
	}
 
 
 
 	function get_module_list_array($id='',$filedir='') 
	{
        $list_array = $this->get_module_data($filedir);
        $temp_list_array = array();     
        foreach($list_array as $key=>$value)
		{
  
		    if($value['id']==$id)
			{
		      
		        $temparray = del_empty_var(explode("|",$value['filedlist'])); 
			    foreach($temparray as $key1=>$value1)
				{ 
				  $temp = array();
		          $temp = del_empty_var(explode(":",$value1)); 
		          $temp_list_array[$temp[0]] = '{$_value.'.$temp[1].'}';					  				
				}	
		        break;
			}

		}	
		return $temp_list_array; 	
	}
 
 	function get_div_data() 
	{   
	    if(empty($this->div_data))
		{
	    $this->div_data = include (ROOT_PATH . '/data/module/module_div.php');
		}
		return $this->div_data;
	}
	
 /* 
				<phpscup:sx type='data' appname='product' action='index'  dataid='1' > 
				     <phpscup:sx type='filedlist' fieldname='url'><phpscup:sx type='filedlist' fieldname='urlvalue'> <phpscup:sx type='filedlist' fieldname='name'> 
                </phpscup:sx > 
 */
 
	function phpdiv_to_sx($str='') 
	{
	    if(empty($str))return $str;
		$temp_html_array = array();	
		$temp_html_array = del_empty_var($this->strAttribute($str));	
		if($temp_html_array['type'] =='data') {
		
       return '<?php		
            $module_list_data = & get_module_list_data();
	        $sx_selectdata = $_sx_selectdata	= array();
	        $_sx_selectdata = unserialize($module_list_data["'.$temp_html_array['appname'].'"]["selectlist"]);			
			$sx_selectdata = $_sx_selectdata['.intval($temp_html_array['dataid']).'] ;
			if ( ! isset( $sx_selectdata.data.0 ) ){
			    $__t__ = array( 0 =>array("name"=>"全部","where"=>"1=1" ));
			    array_splice( $sx_selectdata.data ,0,0,$__t__ );
			}
			foreach ( $sx_selectdata.data as $_key => $_value ) {
			$__sx_url = "?app='.$temp_html_array['appname'].'&act='.$temp_html_array['action'].'&sx=sx" . $sx_selectdata.to .".". $_key ;
            $__sx_urlvalue = "sx" . $sx_selectdata.to .".". $_key ;			
			$__sx_name = $_value.name ;
            ?>';		 
		} else if($temp_html_array['type'] =='filedlist'){
		    if($temp_html_array['fieldname']=='url') {
			    return '<phpscup:url( $__sx_url ) />';
			}else if($temp_html_array['fieldname'] =='name') {
			    return '<?php echo $__sx_name ;?>';
			}else if($temp_html_array['fieldname'] =='urlvalue') {
			    return ' $__sx_urlvalue ';
			}
		}
		
	}

 	function phpdiv_to_htmldiv($str = "",$appname = "") 
	{
	    if(empty($str))return $str;
		$temp_html_array = array();
		$temp_div_array = array();		
		$temp_name = "";	
		$tmep_value1_array = '';			
		$temp_html_array = del_empty_var($this->strAttribute($str));
        $value_array =array();
        if(isset($temp_html_array['name']))
		{
	         $temp_name =str_replace(array('][','[',']'),array('.','.','}'),$temp_html_array['name']);			
		}
        if(isset($temp_html_array['appname']))
		{
                if(empty($appname))
			    {
	             $appname = $temp_html_array['appname'];				
			    }
				else
				{
				 $appname = $this->appname;
				}
		}
      
		foreach($this->get_div_data() as $key => $value)
		{
		    if($temp_html_array['type'] == $value['config']['type'])
			{
			  $temp_div_array = $value;
			}
		}

        if(empty($temp_html_array['value']))
		{
		$temp_html_array['value'] = '{$'.$temp_name;
		}
				
		if(($temp_html_array['value']{0}!= '{'))
		{									 
 			 $temp_value_array = explode("|",$temp_html_array['value']);		 
		 
			 foreach($temp_value_array as $key =>$value)
			 {
				$tmep = explode(":",$value);
				if(!isset($tmep[1]))
				{
				$tmep[1]='';
				}
				$tmep_value1_array[$tmep[0]]=$tmep[1];		     
		     }
		}
		
        if(!empty($temp_html_array['sxdata']))
		{
		    $sx_temp = @include(ROOT_PATH.'/data/sx/'.$temp_html_array['sxdata']);
			$tmep_value1_array=array();
			if(!empty($temp_html_array['sxdatatype']))
			{
			   foreach((array)$sx_temp['data'] as $key => $value)
			   {
				$tmep_value1_array[$value['str_pad'].$value['name']]=$value['name'];				
			   }				
			}
			else
			{
			   foreach((array)$sx_temp['data'] as $key => $value)
			   {
				$tmep_value1_array[$value['str_pad'].$value['name']]=$value['id'];				
			   }			
			}  

			
		}	

		$html_str = '';	
		if(is_array($tmep_value1_array))
		{    
			$html_chird = '';

		    foreach($tmep_value1_array as $key=>$value)
		    {		
		       $value_array = array($key,$value);			   			   
		       if(!empty($temp_div_array['html_chird']))
	           {
		        $html_chird .= preg_replace("/\{PHPSCUP_CONFIG\s*\(\s*(.+?)\s*\)\s*\}/ies", "\$this->_get_config_div('\\1',\$value_array,\$temp_html_array)", $temp_div_array['html_chird']);			 
	           }
			   else
			   {
		        $html_str .= preg_replace("/\{PHPSCUP_CONFIG\s*\(\s*(.+?)\s*\)\s*\}/ies", "\$this->_get_config_div('\\1',\$value_array,\$temp_html_array)", $temp_div_array['html']);				   
			   }
			   			   			   		
		    }
		}
		else
		{
		
		    $html_str .= preg_replace("/\{PHPSCUP_CONFIG\s*\(\s*(.+?)\s*\)\s*\}/ies", "\$this->_get_config_div('\\1',\$value_array,\$temp_html_array)", $temp_div_array['html']);			
		   
		}	
      	    
		if(!empty($temp_div_array['html_chird']))
		{
		        $html_str = preg_replace("/\{PHPSCUP_CONFIG\s*\(\s*(.+?)\s*\)\s*\}/ies", "\$this->_get_config_div('\\1',\$value_array,\$temp_html_array)", $temp_div_array['html']);
								
	            $html_str =str_replace(array('{PHPSCUP_CHIRD}'),array($html_chird),$html_str);
		
		}
		
		$html_str = preg_replace("/\{PHPSCUP_LIST\s*\(\s*(.+?)\s*\)\s*\}/ies", "\$this->_get_list_value_div('\\1',\$appname,\$temp_html_array)", $html_str);	

        return $html_str;

	} 
/*

ICON label:(tablename,fields,order,limit,conditions,pageurl,htmlname,htmlconfig,iconname,iconfields,icondata='一个存数据的文件名',cachedatadir,cachefields,labels).
ICON  example :(<phpscup:icon tablename='content_1.con_id|content.id' fields='content.id:icon2|content_1.my_test:icon1' order='content.add_time desc' limit='0,10' conditions='is_show=1' pageurl='?app=new&act=index&cat=$GLOBALS[cat]' pageiconname='' htmlname='html1' htmlconfig='' iconname='title1' iconfields='' icondata='' cachedatadir='' cachefields='' labels='' powerlimit='scup-leaveword:0-index||job-index&&order-index&&aa-index||pic-index' activetime='2011-12-25 0:30:0,2011-12-25 1:30:0' activebefore='test'  activeafter='test'  activeperiod='test' iconbug='true' tablecachetime='3600' />)

pageiconname属性是指页面分页页面要调用的某个标签的数据的iconname的值，用来调用数据

如果一个标签当中同时读取table,cache,icon数据，则三个数据都会调用到view类中，但显示时可用用不同的显示icon1,icon2等区别开来，如果三个数据同时使用icon1时则先后使用顺序为（从先到后）：icon>cache>table.
powerlimit这个主要用来控制某个用户是否有这个权限，如果用户有这个权限，则这个模块就显示出来，如果没有，就不显示出来，其值的写法是用'-'来区分，第一个可以是scup,admin，如果不写(如leaveword:0-index)，则默认为scup,app是leaveword:0(如果只写leaveword,则自动转化成leaveword:0),act是index，如果要几个权限来控制这个，可以使用||或,&&且来进行逻辑计算，比如scup-leaveword:0-index||job-index&&order-index&&aa-index||pic-index可能会变成'1||0&&1&&1||0',最后计算成1。

(activetime='2011-12-25 0:30:0,2011-12-25 1:30:0' activebefore='test'  activeafter='test'  activeperiod='test' )这四个标签的介绍.如果标签中存在activetime这个时间段，
则activebefore,activeafter,activeperiod分别表示在这个时间段之前该标签应该执行以该属性值为名的一个before的active的类函数,比如test,其文件存在scup/view/default/active/before/中，
比如test.active.before.php，activeafter表示在这个时间段之后执行，activeperiod表示在时间段期间运行，其中注意的是如果以该属性值为名的一个active的类函数有return返回值，则返回值会显示出
来，来代替该标签要显示的内容，也就是该标签的内容不显示了。
如果标签中不存在activetime这个时间段，则activebefore,activeafter,activeperiod分别表示:activebefore表示在运行该标签之前要运行的类函数(与存在activetime这个时间段类似)，
同时如果以该属性值为名的一个active的类函数有return返回值，则返回值会显示出来，来代替该标签要显示的内容，也就是该标签的内容不显示了。activeperiod失效了，activeafter表示在运行该标签之后要运行的类函数
改类的书写方法：文件名是如test.active.after.php,test.active.before.php,test.active.period.php,文件类名都是TestActive,但一定要继承BaseActive比如（class TestActive extends BaseActive）
类函数写法如:  function test() { return '[period]'; }
文件位置如：scup\view\default\active\after，scup\view\default\active\before，scup\view\default\active\period
activetime的值的写法是，两个时间之间用一个“,”号分开（英文状态下）
iconbug='true'的值只能是ture,false主要用来开启标签是否显示调用出来的数据，如果是true则显示，false则不显示，默认是不显示 
tablecachetime='3600'用来设置table表中读出来的数据进行缓存的时间
*/

 	function phpdiv_to_htmlicon($str = "",$temp_icon_array = array(),$appname = "") 
	{
	    if(empty($str)&&empty($temp_icon_array))return $str;
		$oldstr = $this->filtrate($str);
        $tables ='';
		$fields = '';
		$conditions = '';
		$order = '';
		$limit = '';
		$pageurl = '';
		$pageiconname = '';
		$powerlimit = '';
				
        $activetime=''; 
		$activebefore='';  
		$activeafter=''; 
		$activeperiod='';	
		$tablecachetime='0';		

		$icon_str = $icon_str_1 ='';
        $cache_str = $cache_str_1 = '';
        $sql_str = $sql_str_1 = '';
		$str_temp = '';

		$tablename_array = array();
		$fields_array = array();
		$iconfields_array = array(); 
		$cachefields_array = array();
		$activetime_array = array();


        if(empty($temp_icon_array))
		{
		$temp_icon_array = del_empty_var($this->strAttribute($str));		
		}
        if(isset($temp_icon_array['labels'])&&!empty($temp_icon_array['labels']))
		{

        if($GLOBALS['SCup']->SCup_user_msg['data']['view_start_or_stop'])
		{
       return '<!--PHPSCUP:ICON:SET:START--><!--(data=['.$oldstr.'])-->'.'<!--PHPSCUP:ICON:HTMLCODE:START-->'.'<?php '.'if (!defined("PHPSCUPVIEW_MANAGE_SRUE")) '.'{ ?> <?php'.' define("PHPSCUPVIEW_MANAGE_SRUE",1);'.'?>'.'
<SCRIPT LANGUAGE="JavaScript">
var jumpto=true;
function showlabel_(obj,mouse,admin_url,iconname,pagename,data){
	if(mouse=="over"){
		obj.style.filter="Alpha(Opacity=80)";
		obj.style.cursor="hand";
		obj.title="点击修改";
	}else if(mouse=="out"){
		obj.style.filter="Alpha(Opacity=50)";
	}else if(mouse=="click"&&jumpto==true){
		window.self.location=admin_url+"/index.php?app=icon&act=viewmanageedit&weburl='.$this->_urlencode(WEB_URL).'&iconname="+iconname+"&pagename="+pagename+"&data="+data+"&divwidth="+parseInt(obj.style.width)+"&divheight="+parseInt(obj.style.height);
		
	}
}
function ckjump_(type){
	if(type==1){
		jumpto=true;
	}else{
		jumpto=false;
	}
}
</SCRIPT>
		'.'<?php } ?>'.'<div  style="cursor: pointer;border-style:dashed;border-color:red;border-width:1px;z-index: 9998;">        
<div   id="psp_view_manage_'.$temp_icon_array['iconname'].'" style="filter:alpha(opacity=50);position: absolute; border: 1px solid #ff0000; z-index: 9999; color: rgb(0, 0, 0); text-align: left; opacity: 0.4; width: 80px; height:30px; background-color:#A6A6FF;" onmouseover="showlabel_(this,\'over\',\''.SITE_URL.'/admin\',\''.$temp_icon_array['iconname'].'\',\''.$GLOBALS['SCup']->SCup_view->template_filename.'\',\''.$oldstr.'\');" onmouseout="showlabel_(this,\'out\',\''.SITE_URL.'/admin\',\''.$temp_icon_array['iconname'].'\',\''.$GLOBALS['SCup']->SCup_view->template_filename.'\',\''.$oldstr.'\');" onclick="showlabel_(this,\'click\',\''.SITE_URL.'/admin\',\''.$temp_icon_array['iconname'].'\',\''.$GLOBALS['SCup']->SCup_view->template_filename.'\',\''.$oldstr.'\');"><div onmouseover="ckjump_(0);" onmouseout="ckjump_(1);" style="position: absolute; width: 15px; height: 15px;  right: 0px; bottom: 0px; clear: both;font-size: 1px; line-height: 0%;"></div></div>'.'<!--PHPSCUP:ICON:HTMLCODE:END-->'.$temp_icon_array['labels'].'<!--PHPSCUP:ICON:HTMLCODE:START-->'.'<div style="margin: 0px; padding: 0px; border: 0px none; clear: both;"></div></div>'.'<!--PHPSCUP:ICON:SET:END-->';		

		}else
		{
        return '<!--PHPSCUP:ICON:SET:START--><!--(name=['.$temp_icon_array['iconname'].'])-->'.$temp_icon_array['labels'].'<!--PHPSCUP:ICON:SET:END-->';		
		}		
		
	    }

        if(isset($temp_icon_array['order']))
		{
		$order = ''.$temp_icon_array['order'];		
		}

        if(isset($temp_icon_array['limit']))
		{
		$limit = ''.$temp_icon_array['limit'];		
		}

        if(isset($temp_icon_array['conditions']))
		{
		$conditions = ''.$temp_icon_array['conditions'];		
		}

        if(isset($temp_icon_array['pageurl']))
		{
		$pageurl = ''.$temp_icon_array['pageurl'];		
		}
		
        if(isset($temp_icon_array['pageiconname']))
		{
		$pageiconname = ''.$temp_icon_array['pageiconname'];		
		}	
			
        if(isset($temp_icon_array['powerlimit']))
		{
		$powerlimit = ''.$temp_icon_array['powerlimit'];		
		}			
		
	    if(isset($temp_icon_array['activebefore']))
		{
		$activebefore = ''.$temp_icon_array['activebefore'];		
		}	
		
		if(isset($temp_icon_array['activeafter']))
		{
		$activeafter = ''.$temp_icon_array['activeafter'];		
		}
			
		if(isset($temp_icon_array['activeperiod']))
		{
		$activeperiod = ''.$temp_icon_array['activeperiod'];		
		}	
				
        if(isset($temp_icon_array['activetime']))
		{
		$activetime = ''.$temp_icon_array['activetime'];				
		}	
        if(isset($temp_icon_array['tablecachetime']))
		{
		$tablecachetime = intval(trim($temp_icon_array['tablecachetime']));				
		}	
		
        if(isset($temp_icon_array['tablename'])&&!empty($temp_icon_array['tablename']))
		{
		    $temp = $temp1 = array();	
		    $temp = explode("|",$temp_icon_array['tablename']);			
            $temp = $this->del_valueempty_var($temp);
			$num=1;
            foreach($temp as $key => $value)
			{
		        $temp1 = explode(".",$value);
				if(isset($temp1[1]))
				{
				$tablename_array[$num]['table'] = $temp1[0];
				$tablename_array[$num]['field'] = $temp1[1];
				}
				else
				{
				$tablename_array[$num]['table'] = $temp1[0];
				$tablename_array[$num]['field'] = 0;			
				}
				$num++;
			}

		}

        if(isset($temp_icon_array['fields'])&&!empty($temp_icon_array['fields']))
		{
		    $temp = $temp1 = array();	
		    $temp = explode("|",$temp_icon_array['fields']);			
            $temp = $this->del_valueempty_var($temp);
            foreach($temp as $key => $value)
			{
		        $temp1 = explode(":",$value);
				if(isset($temp1[1]))
				{
				$fields_array[$temp1[0]] = $temp1[1];
				}
				else
				{
				$fields_array[$temp1[0]] = 0;				
				}
			}
		}

        if(isset($temp_icon_array['iconfields'])&&!empty($temp_icon_array['iconfields']))
		{
		    $temp = $temp1 = array();	
		    $temp = explode("|",$temp_icon_array['iconfields']);			
            $temp = $this->del_valueempty_var($temp);
            foreach($temp as $key => $value)
			{
		        $temp1 = explode(":",$value);
				if(isset($temp1[0])&&isset($temp1[1]))
				{
				$iconfields_array[$temp1[1]] = $temp1[0];
				}
			}
		}

        if(isset($temp_icon_array['cachefields'])&&!empty($temp_icon_array['cachefields']))
		{
		    $temp = $temp1 = array();	
		    $temp = explode("|",$temp_icon_array['cachefields']);			
            $temp = $this->del_valueempty_var($temp);
            foreach($temp as $key => $value)
			{
		        $temp1 = explode(":",$value);
				if(isset($temp1[0])&&isset($temp1[1]))
				{
				$cachefields_array[$temp1[1]] = $temp1[0];
				}
			}
		}

		if(isset($temp_icon_array['tablename'])&&isset($temp_icon_array['fields'])&&!empty($temp_icon_array['tablename'])&&!empty($temp_icon_array['fields']))
		{     
			  $temp_on = '';
			  $table_pre_key = '';
			  $table_pre_value = '';

            if(count($tablename_array)==1)
			{
			   $tables = DB_PREFIX.$tablename_array[1]['table']. ' '.$tablename_array[1]['table'];
			}
			 else
			{
              for($num=1;$num<=count($tablename_array);$num++)
		      {
				  if(empty($tablename_array[$num]['field'])){$tablename_array[$num]['field'] = ' ';}

                  if(isset($tablename_array[$num+1])&&$num==1)
				  {	

                  $tables.= DB_PREFIX.$tablename_array[$num]['table'] . ' '.$tablename_array[$num]['table'].' LEFT JOIN '.DB_PREFIX.$tablename_array[$num+1]['table'] . ' '.$tablename_array[$num+1]['table'].' ON '. $tablename_array[$num]['table'] .'.'.$tablename_array[$num]['field'].'='. $tablename_array[$num+1]['table'] .'.'.$tablename_array[$num+1]['field'].' ';
				  
				  }
				  else
				  {   
					  if(isset($tablename_array[$num+1]))
					  {
	                  $tables.= ' LEFT JOIN '.DB_PREFIX.$tablename_array[$num+1]['table'] . ' '.$tablename_array[$num+1]['table'].' ON '. $tablename_array[$num]['table'] .'.'.$tablename_array[$num]['field'].'='. $tablename_array[$num+1]['table'] .'.'.$tablename_array[$num+1]['field'].' ';						  
					  }
		  
				  }


		      }	
			  
			}

        foreach($fields_array as $key => $value)
		{
			if(empty($value))
			{
            $fields.= $key . ' ,';			
			}else
			{
            $fields.= $key . ' as '.$value.' ,';			
			}

		}
  			$fields = substr($fields, 0,-1);

			         $sql_str =  'get_view()->assign("fieldlist_'.$temp_icon_array['iconname'].'_db'.'",Page_And_S_Sql_Exe("'.$temp_icon_array['iconname'].'",array("table" => "'.$tables.'","fields" => "'.$fields.'","conditions" => "'.$conditions.'","order" => "'.$order.'","limit" => "'.$limit.'","return" => "all","url" =>"'.$pageurl.'"),'.$tablecachetime.'));';
					 $sql_str_1 =  'get_view()->assign("'.$temp_icon_array['iconname'].''.'",Page_And_S_Sql_Exe("'.$temp_icon_array['iconname'].'",array("table" => "'.$tables.'","fields" => "'.$fields.'","conditions" => "'.$conditions.'","order" => "'.$order.'","limit" => "'.$limit.'","return" => "all","url" =>"'.$pageurl.'"),'.$tablecachetime.'));';

		}
            
        if(isset($temp_icon_array['cachedatadir'])&&!empty($temp_icon_array['cachedatadir'])&&isset($temp_icon_array['cachefields'])&&!empty($temp_icon_array['cachefields']))
		{
             
		     $filename1 = ROOT_PATH . '/'.$temp_icon_array['cachedatadir'];
		     if (file_exists($filename1)) 
		     {
			      if (!is_file($filename1)) 
			      {
                  $cache_str='';
			      $cachefields_array = array();
			      }
				 else
				 {
			      $cache_str =  ' get_view()->assign("fieldlist_'.$temp_icon_array['iconname'].'_cache'.'",get_cache(\''.$filename1.'\')'.');';
				  $cache_str_1 =  ' get_view()->assign("'.$temp_icon_array['iconname'].''.'",get_cache(\''.$filename1.'\')'.');';
				 }
   
		     }
		     else
		    {
             $cache_str='';
			 $cachefields_array = array();
		    }


		}

        if(isset($temp_icon_array['icondata'])&&!empty($temp_icon_array['icondata'])&&isset($temp_icon_array['iconfields'])&&!empty($temp_icon_array['iconfields']))
		{
           
		     $filename2 = $this->icondata_dir . '/icon/icontempdata/'.$temp_icon_array['icondata'].'.icon';
		     if (file_exists($filename2)) 
		     {
			      if (!is_file($filename2)) 
			      {
 		          $iconfields_array = array();       
		          $icon_str = '';
			      }
				 else
				 {
			     $icon_str =  ' get_view()->assign("fieldlist_'.$temp_icon_array['iconname'].'_icon'.'",get_icon_cache(\''.$filename2.'\')'.');';
				 $icon_str_1 =  ' get_view()->assign("'.$temp_icon_array['iconname'].''.'",get_icon_cache(\''.$filename2.'\')'.');';
				 }
   
		     }
		     else
		    {
 		      $iconfields_array = array();       
		     $icon_str = '';
		    }


		}

	    $this->div_icon = include ($this->icondata_dir. '/icon/icon.php');
		$filename = $this->icondata_dir . '/icon/' .$temp_icon_array['htmlname'] . '.html';
		if (file_exists($filename)) 
		{
			if (!is_file($filename)) 
			{
				$html_code = "";
			}

			$html_code = "";
			if (!($html_code = file_get_contents($filename))) 
			{
				$html_code = "";
			}
		}
		else
		{
        $html_code = $this->div_icon[$temp_icon_array['htmlname']]['html'];
		}
		$html_code = preg_replace("/\<phpscup\:filedlist\>(.+?)\<\/phpscup\:filedlist\>/is", "", $html_code);  
        if($temp_icon_array['htmlname']&&!empty($html_code))
		{

            foreach($iconfields_array as $key => $value)
			{
	        $html_code = str_replace($key,$value,$html_code);	
			}

            foreach($cachefields_array as $key => $value)
			{
	        $html_code = str_replace($key,$value,$html_code);	
			}

            $temp_replace_str = '';

			if($sql_str)
			{
            $temp_replace_str = '$fieldlist_'.$temp_icon_array['iconname'].'_db.data';			
			}

			if($cache_str)
			{
            $temp_replace_str = '$fieldlist_'.$temp_icon_array['iconname'].'_cache';			
			}
			if($icon_str)
			{
            $temp_replace_str = '$fieldlist_'.$temp_icon_array['iconname'].'_icon';			
			}
  
			 if($temp_replace_str == '')
			{
			      if(!empty($pageiconname))
				  {
            $temp_replace_str = 'array()';
		    $temp_str = str_replace(array('FIELDLIST_DATA_DEFAULT','FIELDLIST_PAGE','FIELDLIST_DATA_DB','FIELDLIST_DATA_CACHE','FIELDLIST_DATA_ICON'),array($temp_replace_str,'$fieldlist_'.$temp_icon_array['pageiconname'].'_db.page',$temp_replace_str,$temp_replace_str,$temp_replace_str),$html_code);/*数据标签与分页标签替换*/					  
				  }
				  else
				  {
            $temp_replace_str = 'array()';
		    $temp_str = str_replace(array('FIELDLIST_DATA_DEFAULT','FIELDLIST_PAGE','FIELDLIST_DATA_DB','FIELDLIST_DATA_CACHE','FIELDLIST_DATA_ICON'),array($temp_replace_str,$temp_replace_str,$temp_replace_str,$temp_replace_str,$temp_replace_str),$html_code);/*数据标签与分页标签替换*/					  
				  }
		 
			 }
			 else
			{
		    $temp_str = str_replace(array('FIELDLIST_DATA_DEFAULT','FIELDLIST_PAGE','FIELDLIST_DATA_DB','FIELDLIST_DATA_CACHE','FIELDLIST_DATA_ICON'),array($temp_replace_str,'$fieldlist_'.$temp_icon_array['iconname'].'_db.page','$fieldlist_'.$temp_icon_array['iconname'].'_db.data','$fieldlist_'.$temp_icon_array['iconname'].'_cache','$fieldlist_'.$temp_icon_array['iconname'].'_icon'),$html_code);/*数据标签与分页标签替换*/			 
			 }

	
		}
		else
		{ 
				
             if(isset($temp_icon_array['iconbug'])&&$temp_icon_array['iconbug']=='true')
			{
             return '<!--PHPSCUP:ICON:SET:START--><!--(name=['.$temp_icon_array['iconname'].'])-->Get database string :<br/>'.$sql_str.'<br/><br/>Get cached data string :'.$cache_str.'<br/><br/>Get icon array :'.var_export($temp_icon_array , true).'<br/><br/>'.'<!--PHPSCUP:ICON:SET:END-->';	 		 
			}else
			{
            return '<!--PHPSCUP:ICON:SET:START--><!--(name=['.$temp_icon_array['iconname'].'])--><?php '.$sql_str_1.$cache_str_1.$icon_str_1.'?><!--PHPSCUP:ICON:SET:END-->';	
			}

		}

        if($GLOBALS['SCup']->SCup_user_msg['data']['view_start_or_stop'])
		{
				
        return '<!--PHPSCUP:ICON:SET:START--><!--(data=['.$oldstr.'])-->'.'<!--PHPSCUP:ICON:HTMLCODE:START-->'.'<?php '.'if (!defined("PHPSCUPVIEW_MANAGE_SRUE")) '.'{ ?> <?php'.' define("PHPSCUPVIEW_MANAGE_SRUE",1);'.'?>'.'
<SCRIPT LANGUAGE="JavaScript">
var jumpto=true;
function showlabel_(obj,mouse,admin_url,iconname,pagename,data){
	if(mouse=="over"){
		obj.style.filter="Alpha(Opacity=80)";
		obj.style.cursor="hand";
		obj.title="点击修改";
	}else if(mouse=="out"){
		obj.style.filter="Alpha(Opacity=50)";
	}else if(mouse=="click"&&jumpto==true){
		window.self.location=admin_url+"/index.php?app=icon&act=viewmanageedit&weburl='.$this->_urlencode(WEB_URL).'&iconname="+iconname+"&pagename="+pagename+"&data="+data+"&divwidth="+parseInt(obj.style.width)+"&divheight="+parseInt(obj.style.height);
		
	}
}
function ckjump_(type){
	if(type==1){
		jumpto=true;
	}else{
		jumpto=false;
	}
}
</SCRIPT>
		'.'<?php } ?>'.'<div  style="cursor: pointer;border-style:dashed;border-color:red;border-width:1px;z-index: 9998;">        
<div   id="psp_view_manage_'.$temp_icon_array['iconname'].'" style="filter:alpha(opacity=50);position: absolute; border: 1px solid #ff0000; z-index: 9999; color: rgb(0, 0, 0); text-align: left; opacity: 0.4; width: 80px; height:30px; background-color:#A6A6FF;" onmouseover="showlabel_(this,\'over\',\''.SITE_URL.'/admin\',\''.$temp_icon_array['iconname'].'\',\''.$GLOBALS['SCup']->SCup_view->template_filename.'\',\''.$oldstr.'\');" onmouseout="showlabel_(this,\'out\',\''.SITE_URL.'/admin\',\''.$temp_icon_array['iconname'].'\',\''.$GLOBALS['SCup']->SCup_view->template_filename.'\',\''.$oldstr.'\');" onclick="showlabel_(this,\'click\',\''.SITE_URL.'/admin\',\''.$temp_icon_array['iconname'].'\',\''.$GLOBALS['SCup']->SCup_view->template_filename.'\',\''.$oldstr.'\');"><div onmouseover="ckjump_(0);" onmouseout="ckjump_(1);" style="position: absolute; width: 15px; height: 15px;  right: 0px; bottom: 0px; clear: both;font-size: 1px; line-height: 0%;"></div></div>'.'<!--PHPSCUP:ICON:HTMLCODE:END-->'.'<?php '.$sql_str.$cache_str.$icon_str.'?>'.$temp_str.'<!--PHPSCUP:ICON:HTMLCODE:START-->'.'<div style="margin: 0px; padding: 0px; border: 0px none; clear: both;"></div></div>'.'<!--PHPSCUP:ICON:HTMLCODE:END-->'.'<!--PHPSCUP:ICON:SET:END-->';		
		}else
		{

		   $activestr_head_start = '';
		   $activestr_head_else = '';		   
		   $activestr_head_end = '';
		   		   
		   $activestr_footer_start = '';
		   $activestr_footer_else = '';		   	
		   $activestr_footer_end = '';	
		   	   	
           if( $activebefore || $activeafter || $activeperiod )
		   {
			    $activestr_head_start  = ' $activestr = icon_active('."'$activetime','$activebefore','$activeperiod','$activeafter'".'); if ( empty( $activestr ) ) { ';
		        $activestr_head_else = ' } else { ?> {$activestr} ';		       
			    $activestr_head_end = '<?php  } ';				
					
			    if($activeafter&&empty($activetime))
				{
		           $activestr_footer_start = ' icon_active('."'$activetime','$activebefore','$activeperiod','$activeafter'".'); ';
		           $activestr_footer_else = '';		   	
		           $activestr_footer_end = '';							
				}
			    if($activeperiod&&empty($activetime))
				{
		           $activestr_head_start = ' ';
		           $activestr_head_else = ' ';		   
		           $activestr_head_end = ' ';									
				}
			    if($activebefore&&empty($activetime))
				{				
			    $activestr_head_start  = ' $activestr = icon_active('."'$activetime','$activebefore','$activeperiod','$activeafter'".'); if ( empty( $activestr ) ) { ';
		           $activestr_head_else = ' } else { ?> {$activestr} ';		       
			       $activestr_head_end = '<?php  } ';							
				}	

		   }		   	
						
		   if($powerlimit)
		   {
            return '<!--PHPSCUP:ICON:SET:START--><!--(name=['.$temp_icon_array['iconname'].'])--><?php if (icon_power_limit("'.$powerlimit.'")) { '.$activestr_head_start.$sql_str.$cache_str.$icon_str.'?>'.$temp_str.'<?php '.$activestr_head_else.$activestr_head_end.$activestr_footer_start.' }?> <!--PHPSCUP:ICON:SET:END-->';	
		   }else
		   {
            return '<!--PHPSCUP:ICON:SET:START--><!--(name=['.$temp_icon_array['iconname'].'])--><?php '.$activestr_head_start.$sql_str.$cache_str.$icon_str.'?>'.$temp_str.'<?php '.$activestr_head_else.$activestr_head_end.$activestr_footer_start.' ?><!--PHPSCUP:ICON:SET:END-->';			
		   }
			
		}
				
	} 

	function _urlencode($msg){
		$msg = str_replace('-',';gang;',$msg);
		$msg = urlencode($msg);		
		return $msg;
	}

	function filtrate($msg){
		$msg = str_replace('=',';deng;',$msg);
		$msg = str_replace(' ',';kong;',$msg);
		$msg = str_replace('"',';shuang;',$msg);
		$msg = str_replace("'",';dang;',$msg);
		$msg = str_replace("&&",';and;',$msg);		
		$msg = str_replace("||",';or;',$msg);
		$msg = str_replace("-",';gang;',$msg);					
		return $msg;
	}

function strAttribute($str='',$SourceMaxSize = 1024,$CharToLow = FALSE)
{
	    $Items =array();
        $Count = -1;
		$strLen = 0;
		$d = "";
		$tmpatt="";
		$tmpvalue="";
		$startdd=-1;
		$ddtag="";
		$j = 0;
		$str = trim(preg_replace("/[ \t\r\n]{1,}/"," ",$str));
		$strLen = strlen($str);
		$str .= " ";
   if($strLen>0&&$strLen<=$SourceMaxSize)
   {
	   //遍历源字符串，获得各属性
		for($i=$j;$i<$strLen;$i++)
		{
			$d = $str[$i];
			//获得属性的键
			if($startdd==-1){
				if($d!="=")	$tmpatt .= $d;
				else{
					$tmpatt = strtolower(trim($tmpatt));
					$startdd=0;
				}
			}
			//检测属性值是用什么包围的，允许使用 '' "" 或空白
			else if($startdd==0){
				switch($d){
					case ' ':
						continue;
						break;
					case '\'':
						$ddtag='\'';
						$startdd=1;
						break;
					case '"':
						$ddtag='"';
						$startdd=1;
						break;
					default:
						$tmpvalue.=$d;
						$ddtag=' ';
						$startdd=1;
						break;
				}
			}
			//获得属性的值
			else if($startdd==1)
			{
				if($d==$ddtag){
					$Count++;
          if($CharToLow) $Items[$tmpatt] = strtolower(trim($tmpvalue));
					else $Items[$tmpatt] = trim($tmpvalue);
					$tmpatt = "";
					$tmpvalue = "";
					$startdd=-1;
				}
				else
					$tmpvalue.=$d;
			}
	  }//End for
	  //处理没有值的属性(必须放在结尾才有效)如："input type=radio name=t1 value=aaa checked"


	  if($tmpatt!="")
	  { 
		  $Items[$tmpatt] = "";
	  }

        return $Items;

  }

  return '';
        

}



    function _get_content_html($str="",$temp_array= array(),$tips=array())
	{   
		$str = preg_replace("/\<\!\-\-PHPSCUP\:DELSTART\-\-\>\s*(.+?)\s*\<\!\-\-PHPSCUP\:DELEND\-\-\>/ies", "\$this->_content_html_del('\\1')", $str);
		$str = str_replace(array("<!--PHPSCUP:DELSTART-->","<!--PHPSCUP:DELEND-->"),array(' ',' '),$str);
		
		$html_str = preg_replace("/\<\!\-\-PHPSCUP\:START\>\s*(.+?)\s*\<PHPSCUP\:END\-\-\>/ies", "\$this->_content_html_deal('\\1',\$temp_array,\$tips)", $str);
		
		return stripslashes($html_str);
	}
    function _content_html_del($str="")
	{  
       return '';
	}

    function _content_html_deal($str="",$temp_array=array(),$tips=array())
	{  
	   if(empty($temp_array))
	   {
	   return '<!--PHPSCUP:START>'.$str.'<PHPSCUP:END-->';
	   }
	   $temp_str = '<!--PHPSCUP:START>'.$str.'<PHPSCUP:END--><!--PHPSCUP:DELSTART-->'; 
	   foreach($temp_array as $key =>$value)
	   { 
	        $temp_str .= str_replace(array("<PHPSCUP:LIST_ICON>","<PHPSCUP:LIST_CODE>","<PHPSCUP:CONTENT_ICON>","<PHPSCUP:CONTENT_CODE>","<PHPSCUP:CONTENT_TIPS>"),array($key,$value,$key,$value,$tips[$key]),$str);	      

	   }
 
       return $temp_str.'<!--PHPSCUP:DELEND-->';
	}

    function _get_list_value_div($vname="",$appname="",$html_array=array())
	{  
	    $str = '';
		if($vname=='appname')
		{
		 return $appname;
		}
        if(isset($html_array[$vname]))
		{ 
		    if($vname=='name')
			{
			    $filterdata = $GLOBALS['SCup']->SCup_filter_app->_table_list;
				foreach ($filterdata['s'] as $key => $value)
				{
				  $filterdata['s'][$key] = '_'.$key.'_';
				}				
				$t_array = array("data[","]","_s_") + $filterdata['s'];

				$t=array();
				for( $i = 0  ; $i<count($t_array); $i++)
				{
				$t[$i] = "";
				}	
               	$str = str_replace('][','.',$html_array[$vname]); 			
		        $str = str_replace($t_array,$t,$str); 
			}
			else
			{
			$str = $html_array[$vname];
			}
		}	
		return $str;
	}


    function _get_config_div($str="",$value_array=array(),$html_array=array())
	{   

	    $temp_str='';
  		$temp_array = del_empty_var(explode("&",$str));

		if(empty($temp_array))
		{
		    foreach($html_array as $key=>$value)
			{
			      if(($value=='disabled'||$value=='selected'||$value=='checked')&&!isset($html_array[$value]))
			      {
	               continue;			
			      }			
	              $temp_str .=  ' '.$key."=\"".$value."\" "; 			
			}
			return $temp_str;		
		}
		
        if(empty($value_array))
		{
             foreach($temp_array as $key=>$value)
		     {	
			      if(($value=='disabled'||$value=='selected'||$value=='checked')&&!isset($html_array[$value]))
			      {
	               continue;			
			      }			 
			    if($value =='ICON')
			     {
				  return $html_array['value'];			  
				 }
			     if(!isset($html_array[$value]))
				 {
				  $html_array[$value] ='';
				 }
			     $temp_str .=' '.$value."=\"".$html_array[$value]."\" ";		
		     }	
			 return $temp_str;	
		} 	
			
        if(!empty($value_array))
		{
             foreach($temp_array as $key=>$value)
		     {
			      if(($value=='disabled'||$value=='selected'||$value=='checked')&&!isset($html_array[$value]))
			      {
	               continue;			
			      }
				    
			 	 if($value =='ICON')
			     {
				  return $value_array[0];			  
				 }
				 
			 	 if($value =='ICONK')
			     {
				  return $value_array[1];			  
				 }
				 				 
				 if($value =='value')
				 {   
				     if(isset($value_array[1]))
					 {
			         $temp_str .=' '.$value."=\"".$value_array[1]."\" ";						 
					 }
					 else
					 {
			         $temp_str .=' '.$value."=\"".$value_array[0]."\" ";						 
					 }
			 
				 }
				 else
				 {
				 	 if(!isset($html_array[$value]))
				     {
				     $html_array[$value] ='';
				     }
			         $temp_str .=' '.$value."=\"".$html_array[$value]."\" ";				 
				 }
				 
		
		     }	
			 return $temp_str;	
		} 


    }


    function del_empty_var($array)
	{ 
	     foreach($array as $key => $value)
	     {
	        if(empty($value)&&empty($key))
	        {
	          unset($array[$key]);
	        }
	        if(($key=='disabled'&&empty($value))||($key=='selected'&&empty($value))||($key=='checked'&&empty($value)))
			{
	          unset($array[$key]);			
			}
	     }
	     return $array;
     }

    function del_valueempty_var($array)
	{ 
	     foreach($array as $key => $value)
	     {
	        if(empty($value))
	        {
	          unset($array[$key]);
	        }
	     }
	     return $array;
     }
 
  	function get_phpscupdiv( $id = 0,$appname = '',$filedir='') 
	{
	    $phpscupdiv_data = array();
	    $moduledata = $this->get_module_data($filedir);
	
		foreach($moduledata as $key => $value)
		{
		      if(!isset($value['appname']))
			  {
			  $value['appname'] ='';
			  }
		      if($id&&($value['id']==$id))
		      {
		       $tempdata = $value;		 
		      }		 
		      if($appname&&($value['appname']==$appname))
		      {
		      $tempdata = $value;		 
		      } 		
		}
									
		$module_config = unserialize($tempdata['config']);

        if(!is_array($module_config))$module_config = array();

		$phpdivdata = $this->get_div_data();

		foreach($module_config as $key => $value)
		{   
            $phpscupdiv_data[$key]['fieldname'] = $value['filed']['name'];
			$temp_phpscupdiv = '';
		 	foreach($phpdivdata as $key2 => $value2)
		    {
		       if($value2['config']['type'] == $value['form']['type'])
			   {
			    $temp_phpscupdiv = $value2['phpscupdiv'];
			   }
		    }
			
	   	   $temp_str = "type='".$value['form']['type']."' ";
		   $phpscupdiv_data[$key]['icon'] = $value['form']['icon'];
		   foreach($value['form'][$value['form']['type']] as $key1 => $value1)
		   {
            $temp_str .= $key1."='". $value1."' "; 
		   }
           $temp_str = $temp_str ." appname='".$this->appname."' ";
           $temp_str = $temp_str ." sxdata='".$value['form']['sx_data']."' ";
           $temp_str = $temp_str ." sxdatatype='".$value['form']['sxdatatype']."' ";	
		   $phpscupdiv_data[$key]['tips'] = $value['form']['tips'];		   	   		   
		   $phpscupdiv_data[$key]['phpdiv'] = str_replace(array('PHPSCUP_DIV',"<",">"),array($temp_str,"&lt;","&gt;"),$temp_phpscupdiv);
		   
		   $phpscupdiv_data[$key]['htmldiv'] = str_replace(array("<",">"),array("&lt;","&gt;"),$this->phpdiv_to_htmldiv($temp_str,$this->appname)); 
		   
		}		
        return $phpscupdiv_data;
	} 



}


?>